/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Bienvenido.java
 *
 * Created on 09-jul-2012, 13:47:21
 */
package GUI;

import com.sun.spot.peripheral.Spot;
import com.sun.spot.peripheral.ota.OTACommandServer;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.jfree.ui.RefineryUtilities;
import org.sunspotworld.ConexionBD;
import org.sunspotworld.Cosecha;
import org.sunspotworld.CosechaDialog;
import org.sunspotworld.HidroponiaHost;
import org.sunspotworld.LoginDialog;
import org.sunspotworld.Usuario;
import org.sunspotworld.hiloCosecha;
import org.sunspotworld.HiloSensoresExternos;
import org.sunspotworld.HiloSensoresInternos;
import org.sunspotworld.RiegosReporte;
import org.sunspotworld.SensoresExternos;
import org.sunspotworld.SensoresInternos;

/**
 *
 * @author andresgodoysalavert
 */
public class Bienvenido extends javax.swing.JFrame {
    
    ConexionBD con = new ConexionBD();

    /** Creates new form Bienvenido */
    public Bienvenido() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        dateChooserPanel1 = new datechooser.beans.DateChooserPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        regandoLabel = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        dateChooserPanel1.setCurrentView(new datechooser.view.appearance.AppearancesList("Bordered",
            new datechooser.view.appearance.ViewAppearance("custom",
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    true,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 255),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(128, 128, 128),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(255, 0, 0),
                    false,
                    false,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                (datechooser.view.BackRenderer)null,
                false,
                true)));
    dateChooserPanel1.setCalendarBackground(new java.awt.Color(51, 51, 51));
    dateChooserPanel1.setNavigateFont(new java.awt.Font("Tahoma", java.awt.Font.BOLD, 16));
    dateChooserPanel1.setCurrentNavigateIndex(1);
    dateChooserPanel1.addSelectionChangedListener(new datechooser.events.SelectionChangedListener() {
        public void onSelectionChange(datechooser.events.SelectionChangedEvent evt) {
            dateChooserPanel1OnSelectionChange(evt);
        }
    });

    jLabel4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_21381797989_calendar.png")); // NOI18N

    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);

    jTextArea2.setColumns(20);
    jTextArea2.setRows(5);
    jScrollPane2.setViewportView(jTextArea2);

    org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(jPanel3Layout.createSequentialGroup()
            .add(jScrollPane2)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
            .add(jLabel4)
            .addContainerGap())
        .add(jScrollPane1)
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(jPanel3Layout.createSequentialGroup()
            .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jLabel4)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(jScrollPane1))
    );

    jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Horarios de Riego", "Reportes de Cosecha", "Panel Manual" }));
    jComboBox1.setToolTipText("");

    jButton1.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
    jButton1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_31381796141_ledtarrow.png")); // NOI18N
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
    jButton2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_11381795534_user.png")); // NOI18N
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    jButton3.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
    jButton3.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_31381796134_key.png")); // NOI18N
    jButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton3ActionPerformed(evt);
        }
    });

    jLabel3.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\logop.png")); // NOI18N

    jButton4.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
    jButton4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_1381796187_cross.png")); // NOI18N
    jButton4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton4ActionPerformed(evt);
        }
    });

    jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_1rsz_help_browser.png")); // NOI18N
    jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jLabel2MouseClicked(evt);
        }
    });

    org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(jLabel2)
                    .add(10, 10, 10)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 686, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(dateChooserPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 884, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(18, 18, 18)
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(jLabel3)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 17, Short.MAX_VALUE)
                    .add(jButton4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                    .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                    .add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jComboBox1)
                            .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 62, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(jLabel3)
                        .add(14, 14, 14)))
                .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                    .add(jLabel2)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)))
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(dateChooserPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE))
            .add(27, 27, 27))
    );

    jPanel2.setBackground(new java.awt.Color(153, 153, 153));
    jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    jPanel2.setLayout(new java.awt.GridLayout(1, 8));

    jPanel4.setBackground(new java.awt.Color(204, 204, 204));
    jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
    jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_1381795404_bandwidth-px-png.png")); // NOI18N
    jLabel1.setText("Medidores");

    regandoLabel.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
    regandoLabel.setForeground(new java.awt.Color(255, 0, 0));
    regandoLabel.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_1rsz_1rsz_1rsz_water-droplet-psd55437.png")); // NOI18N
    regandoLabel.setText("  REGANDO");

    jLabel5.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
    jLabel5.setIcon(new javax.swing.ImageIcon("C:\\Users\\Salaver\\Documents\\NetBeansProjects\\host\\trunk\\HidroponiaDesktop\\img\\rsz_1tea-plant-leaf-icon.png")); // NOI18N
    jLabel5.setText("Proximo Riego:");

    org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
        jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(jPanel4Layout.createSequentialGroup()
            .addContainerGap()
            .add(jLabel1)
            .add(407, 407, 407)
            .add(regandoLabel)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jLabel5)
            .add(20, 20, 20))
    );
    jPanel4Layout.setVerticalGroup(
        jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
            .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jLabel1)
                .add(regandoLabel)
                .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
            .add(30, 30, 30))
    );

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 187, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (HidroponiaHost.usuario.getCargo().equals("Administrador")){
        if (jComboBox1.getSelectedItem() == "Panel Manual"){
            Panel panel = new Panel();
            panel.setVisible(true);
        }
        if (jComboBox1.getSelectedItem() == "Horarios de Riego"){
            Tiempos tiempos = new Tiempos();
            tiempos.setVisible(true);
        }
        if (jComboBox1.getSelectedItem() == "Reportes de Cosecha"){
            
            HidroponiaHost.reportes.setVisible(true);
        }
        } else{
            if (jComboBox1.getSelectedItem() == "Reportes de Cosecha"){
            HidroponiaHost.reportes.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(this,
            "Debe ser administrador para poder ingresar a alguna de las opciones",
            "Advertencia",
            JOptionPane.WARNING_MESSAGE);
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        if (HidroponiaHost.usuario.getCargo().equals("Administrador")){
            AdminUsuario admin = new AdminUsuario();
            admin.setVisible(true);
        }else{
            JOptionPane.showMessageDialog(this,
            "Debe ser administrador para poder ingresar a alguna de las opciones",
            "Advertencia",
            JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void dateChooserPanel1OnSelectionChange(datechooser.events.SelectionChangedEvent evt) {//GEN-FIRST:event_dateChooserPanel1OnSelectionChange
        // TODO add your handling code here:
        if (HidroponiaHost.cosecha.getId() > 0){    
            String texto = "Informacion para la fecha ";
            try {
                con.conectar();
                SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                SimpleDateFormat hora = new SimpleDateFormat("HH:mm");
                Calendar cal = dateChooserPanel1.getSelectedDate();
                Date date = cal.getTime();
                String seleccion = sdf.format(date);
                texto = texto+seleccion;
                String query1 = "SELECT ec.fecha_inicio, ec.fecha_fin, e.nombre FROM etapa_cosecha ec, etapa e WHERE ec.etapa_id=e.id AND cosecha_id="+HidroponiaHost.cosecha.getId();
                
                ResultSet rs1 = con.consultar(query1);
                while (rs1.next()){
                    if (rs1.getString(1)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs1.getString(1))))){
                        texto = texto+"\nSe inicio la "+rs1.getString(3)+" a la hora: "+hora.format(hora.parse(rs1.getString(1).substring(11, 16)));
                    }
                    }
                    if (rs1.getString(2)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs1.getString(2))))){
                        texto = texto+"\nSe finalizo la "+rs1.getString(3)+" a la hora: "+hora.format(hora.parse(rs1.getString(2).substring(11, 16)));
                    }
                    }
                }
                
                if (HidroponiaHost.cosecha.semillero != null){
                    String query5 = "SELECT hora_inicio, hora_fin FROM semillero_riego WHERE semillero_id="+HidroponiaHost.cosecha.semillero.getId();
                ResultSet rs5 = con.consultar(query5);
                while (rs5.next()){
                    if (rs5.getString(1)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs5.getString(1)))) && (sdf.format(sdf.parse(rs5.getString(1)))!=null)){
                        texto = texto+"\nSe inicio un riego al semillero a la hora: "+hora.format(hora.parse(rs5.getString(1).substring(11, 16)));
                    }
                    }
                    if (rs5.getString(2)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs5.getString(2))))){
                        texto = texto+"\nSe finalizo un riego al semillero a la hora: "+hora.format(hora.parse(rs5.getString(2).substring(11, 16)));
                    }
                    }
                }
                }
                
                if (HidroponiaHost.cosecha.mezcla != null){
                String query2 = "SELECT mm.fecha, mm.valor, m.nombre, m.unidad FROM medidor_mezcla mm, medidor m WHERE mm.medidor_id=m.id AND mezcla_id="+HidroponiaHost.cosecha.mezcla.getId();
                String query3 = "SELECT hora_inicio, hora_fin FROM mezcla_riego WHERE mezcla_id="+HidroponiaHost.cosecha.mezcla.getId();
                String query4 = "SELECT nm.hora_inicio, n.nombre FROM nutriente_mezcla nm, nutriente n WHERE nm.nutriente_id=n.id AND mezcla_id="+HidroponiaHost.cosecha.mezcla.getId();
                
                ResultSet rs3 = con.consultar(query3);
                while (rs3.next()){
                    if (rs3.getString(1)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs3.getString(1))))){
                        texto = texto+"\nSe inicio un riego NFT a la hora: "+hora.format(hora.parse(rs3.getString(1).substring(11, 16)));
                    }
                    }
                    if (rs3.getString(2)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs3.getString(2))))){
                        texto = texto+"\nSe finalizo un riego NFT a la hora: "+hora.format(hora.parse(rs3.getString(2).substring(11, 16)));
                    }
                    }
                }
                ResultSet rs2 = con.consultar(query2);
                while (rs2.next()){
                    if (rs2.getString(1)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs2.getString(1))))){
                        texto = texto+"\nEl sensor "+rs2.getString(3)+" registro un valor de: "+rs2.getInt(2)+" "+rs2.getString(4);
                    }
                    }
                }
                ResultSet rs4 = con.consultar(query4);
                while (rs4.next()){
                    if (rs4.getString(1)!=null){
                    if (seleccion.equals(sdf.format(sdf.parse(rs4.getString(1))))){
                        texto = texto+"\nSe hecho una dosis de "+rs4.getString(2)+" a las: "+rs2.getInt(2);
                    }
                    }
                }
                }
                HidroponiaHost.bienvenido.jTextArea1.setText(texto);
            } catch (SQLException ex) {
                Logger.getLogger(Bienvenido.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ParseException ex) {
                Logger.getLogger(Bienvenido.class.getName()).log(Level.SEVERE, null, ex);
            } 
        } else {
        
        }
    }//GEN-LAST:event_dateChooserPanel1OnSelectionChange

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        if (HidroponiaHost.usuario.getCargo().equals("Administrador")){
            try {
                con.conectar();
                Date now = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
                String query5 = "UPDATE etapa_cosecha SET fecha_fin='"+sdf.format(now)+"' WHERE cosecha_id="+HidroponiaHost.cosecha.getId()+" AND etapa_id="+HidroponiaHost.cosecha.etapa.getId();
                System.out.println("QUERY "+query5);
                con.insertar(query5);
                HidroponiaHost.cosecha = new Cosecha();
                HidroponiaHost.estado = 0;
                        HidroponiaHost.cosecha.setId(0);
                        HidroponiaHost.hiloC.terminarCosecha();
                        HidroponiaHost.hiloS.terminarCosecha();
                        HidroponiaHost.hiloE.terminarCosecha();
                        HidroponiaHost.bienvenido.jLabel5.setText("Proximo riego:");
                        HidroponiaHost.bienvenido.regandoLabel.setVisible(false);
                        HidroponiaHost.bienvenido.jTextArea1.setText("");
                        HidroponiaHost.bienvenido.jTextArea2.setText("");
                        HidroponiaHost.dialesT.setValor(15);
                        HidroponiaHost.dialesPH.setValor(3);
                        HidroponiaHost.dialesA.setValor(0);
                        HidroponiaHost.diales1.setValor(0);
                        HidroponiaHost.diales2.setValor(0);
                        HidroponiaHost.diales3.setValor(0);
                        HidroponiaHost.diales4.setValor(0);
                        Object[] options = {"Si, crear",
                        "No, cerrar sistema"};
                        int n = JOptionPane.showOptionDialog(HidroponiaHost.bienvenido,
                        "Ha cancelado la cosecha! \nDesea iniciar una nueva o salir del sistema?",
                        "Aviso",
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,     //do not use a custom Icon
                        options,  //the titles of buttons
                        options[0]); //default button title
                        if (n == 0){
                                CosechaDialog cosechad = new CosechaDialog(null);
                                cosechad.setVisible(true);
                                //default title and icon
                                JOptionPane.showMessageDialog(HidroponiaHost.bienvenido,
                                "Creando nueva cosecha. \n*Recuerde preparar las componentes del sistema \n*Presione OK cuando este listo");
                                HidroponiaHost.hiloC = new hiloCosecha();
                                HidroponiaHost.hiloS = new HiloSensoresExternos();
                                HidroponiaHost.hiloE = new HiloSensoresInternos();
                                HidroponiaHost.hiloC.estado = 1;
                                HidroponiaHost.hiloC.start();
                        } else{
                            //default title and icon
                            JOptionPane.showMessageDialog(HidroponiaHost.bienvenido,
                            "Gracias por usar Hidroponia Smart!, hasta pronto..");
                            System.exit(0);
                        }
                        con.desconectar();
            } catch (SQLException ex) {
                Logger.getLogger(Bienvenido.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else{
            JOptionPane.showMessageDialog(this,
            "Debe ser administrador para poder ingresar a alguna de las opciones",
            "Advertencia",
            JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:  
        if (HidroponiaHost.usuario.getCargo().equals("Administrador")){
            HidroponiaHost.usuario = new Usuario();
            LoginDialog login = new LoginDialog(this);
            login.setVisible(true);
        } else{
            LoginDialog login = new LoginDialog(this);
            login.setVisible(true);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
        // TODO add your handling code here:
        Ayuda ayuda = new Ayuda();
        ayuda.setVisible(true);
    }//GEN-LAST:event_jLabel2MouseClicked

    /**
     * @param args the command line arguments
     */

    
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Bienvenido().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private datechooser.beans.DateChooserPanel dateChooserPanel1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    public javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    public javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    public javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    public javax.swing.JTextArea jTextArea1;
    public javax.swing.JTextArea jTextArea2;
    public javax.swing.JLabel regandoLabel;
    // End of variables declaration//GEN-END:variables
}
